package com.thon.entity.project;

// Generated 2013-9-23 19:12:56 by Hibernate Tools 3.4.0.CR1

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.thon.commons.config.Global;
import com.thon.entity.util.IdEntity;

/**
 * MeProjectAd generated by hbm2java
 */
@Entity
@Table(name = "project_ads")
@JsonIgnoreProperties(ignoreUnknown=true)
public class ProjectAd extends IdEntity {

	private static final long serialVersionUID = -5780328701137953985L;
	private Project project;
	private String content;
	private Date createdDate;
	private String title;

	public ProjectAd() {
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "project_id", nullable = false)
	public Project getProject() {
		return this.project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public String getContent() {
		if(!StringUtils.isBlank(content)){
			content = StringEscapeUtils.unescapeHtml4(content);
			content = content.replaceAll("src=\"../common/attachment/download/", "src=\""+Global.getConfig("img.url"));
		}
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

}
